package com.bindapp.model;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.bindapp.R;
import com.bindapp.databinding.ActivitySclBinding;
import com.bindapp.util.TextUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by apple on 2018/7/9.
 */

public class ControllerSclModel extends BaseModel {
    private ActivitySclBinding binding;
    private List<TextView> textViewList=new ArrayList<TextView>();
    public ControllerSclModel(Context context){
        super(context);
        binding= DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.activity_scl,null,false);
        binding.setClick(new ViewClick());
        textViewList.add(binding.label9);
        textViewList.add(binding.label10);
        textViewList.add(binding.label11);
        binding.switch4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                binding.status.setText(b?"开":"关");
            }
        });
        TextUtil.utilTxtColor(binding.status,"*功能开启前，请确认浴缸内没有人员",1,ContextCompat.getColor(context,R.color.red_btn_bg_color),ContextCompat.getColor(context,R.color.textcolor));
        binding.switch4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    binding.status.setVisibility(View.GONE);
                }else{
                    binding.status.setVisibility(View.VISIBLE);
                }
            }
        });
    }
    @Override
    public ActivitySclBinding getBinding() {
        return binding;
    }

    public class ViewClick{
        public void onClick(View view){
            switch(view.getId()){
                case R.id.label9:
                    setStatusChange((TextView)view,R.drawable.round_tab_blue);
                    break;
                case R.id.label10:
                    setStatusChange((TextView)view,R.drawable.round_tab_red);
                    break;
                case R.id.label11:
                    setStatusChange((TextView)view,R.drawable.round_tab_green);
                    break;
            }
        }
    }

    public void setStatusChange(TextView textview,int draw){
        for(TextView view:textViewList){
            view.setBackground(null);
            view.setTextColor(ContextCompat.getColor(context,R.color.textcolor));
        }
        textview.setBackground(ContextCompat.getDrawable(context,draw));
        textview.setTextColor(Color.WHITE);
    }
}
